﻿using MediatR;
using Traceability.App.Api.Application.Command.Get;
using Traceability.App.Domain;
using Traceability.App.ErrorCode;
using Traceability.App.Instructure;

namespace Traceability.App.Api.Application.Handler.Get
{
    public class GetDeepProcessingHandler : IRequestHandler<GetDeepProcessingCommand, ApiResult<DeepProcessing>>
    {
        private readonly IBaseRepository<DeepProcessing> deepRepo;

        public GetDeepProcessingHandler(IBaseRepository<DeepProcessing> deepRepo)
        {
            this.deepRepo = deepRepo;
        }
        public Task<ApiResult<DeepProcessing>> Handle(GetDeepProcessingCommand request, CancellationToken cancellationToken)
        {
            ApiResult<DeepProcessing> res = new ApiResult<DeepProcessing>();
            var deep = deepRepo.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            res.Data = deep;
            res.Code = ApiEnum.Success;
            res.Msg = "显示深加工信息成功";
            return Task.FromResult(res);
        }
    }
}
